module.exports = {
	countdown : 60,
	//发送验证码倒计时
	settime : function(obj) {
		var that = this;
		if (that.countdown == 0) {
			obj.setAttribute("rel", 'send');
			obj.innerHTML = "重新发送";
			obj.className += ' codeBtn';
			that.countdown = 60;
			return;
		} else {
			obj.removeAttribute("rel");
			obj.innerHTML = "重新发送(" + that.countdown + 's' + ")";
			that.countdown--;
		}
		setTimeout(function() {
			that.settime(obj)
		}, 1000)
	},
	//秒杀倒计时
	countTime : function(_date, callback) {
		var that = this;
		//获取当前时间
		var date = new Date();
		var now = date.getTime();
		//设置截止时间
		_date = _date.replace(/-/g, '/'); 
		var endDate = new Date(_date);
		var end = endDate.getTime();
		//时间差
		var leftTime = end - now;
		//定义变量 d,h,m,s保存倒计时的时间
		var d, h, m, s;
		if (leftTime >= 0) {
			d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
			h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
			m = Math.floor(leftTime / 1000 / 60 % 60);
			s = Math.floor(leftTime / 1000 % 60);
			
			h = (h+"").length == 1 ? '0'+h : h;
			m = (m+"").length == 1 ? '0'+m : m;
			s = (s+"").length == 1 ? '0'+s : s;
			//将倒计时赋值到div中
			//obj.find('[rel="_d"]').html(d);
			//obj.find('[rel="_h"]').html(h);
			//obj.find('[rel="_m"]').html(m);
			//obj.find('[rel="_s"]').html(s);
			
			if(d>0) {
				document.getElementById("t_day").innerHTML = d+'日';
			}
			document.getElementById("t_hour").innerHTML = h;
			document.getElementById("t_minute").innerHTML = m;
			document.getElementById("t_second").innerHTML = s;

			//递归每秒调用countTime方法，显示动态时间效果
			setTimeout(function() {
				that.countTime(_date, callback);
			}, 1000);
		} else {
			$.isFunction(callback) && callback();
		}
	},
	countTimeMuti : function(_obj, callback) {
		var that = this;
		//获取当前时间
		var date = new Date();
		var now = date.getTime();
		//设置截止时间
		var _date = _obj.data('startdate');
		_date = _date.replace(/-/g, '/'); 
		var endDate = new Date(_date);
		var end = endDate.getTime();
		//时间差
		var leftTime = end - now;
		//定义变量 d,h,m,s保存倒计时的时间
		var d, h, m, s;
		if (leftTime >= 0) {
			d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
			h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
			m = Math.floor(leftTime / 1000 / 60 % 60);
			s = Math.floor(leftTime / 1000 % 60);
			
			h = (h+"").length == 1 ? '0'+h : h;
			m = (m+"").length == 1 ? '0'+m : m;
			s = (s+"").length == 1 ? '0'+s : s;
			//将倒计时赋值到div中
			
			_obj.find('.t_hour').text(h);
			_obj.find('.t_minute').text(m);
			_obj.find('.t_second').text(s);

			//递归每秒调用countTime方法，显示动态时间效果
			setTimeout(function() {
				that.countTimeMuti(_obj, callback);
			}, 1000);
		} else {
			$.isFunction(callback) && callback();
		}
	},
	//展示时间类型
	showMusicTimeText: function(duration) {
		if(duration<10) return '00:0'+duration.toFixed(0);
		var _m = Math.floor(duration/60).toFixed(0);
		if(_m < 10) _m = '0'+_m;
		var _s = Math.floor(duration%60).toFixed(0);
		if(_s < 10) _s = '0'+_m;
		return _m+':'+_s;
	}
}